package com.business.fallback;

import com.business.api.UserApi;
import com.comm.entity.po.LoginUserInfo;
import com.comm.enums.FeignErrorEnum;
import com.comm.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO 用户操作熔断处理
 * @Author: mis_wu
 * @Date: 2022/7/20
 **/
@Slf4j
@Component
public class UserApiFallbackImpl implements FallbackFactory<UserApi> {

    public static class UserFallbackImpl implements UserApi{

        private final Throwable throwable;

        private UserFallbackImpl(Throwable throwable){
            this.throwable = throwable;
        }

        @Override
        public ResponseResult<LoginUserInfo> userLoginVerify(LoginUserInfo loginUserInfo) {
            log.error("用户登录失败,方法:userLoginVerify,参数:{},异常:{}",loginUserInfo,throwable.getMessage());
            return ResponseResult.feignError(FeignErrorEnum.FEIGN_USER_LOGIN_FAIL,throwable);
        }
    }

    @Override
    public UserApi create(Throwable throwable) {
        return new UserFallbackImpl(throwable);
    }
}
